package com.liu.ai.chat;

import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;

public class OpenAiChat {

    private static final String apiKey = "sk-d1c41de66c074fc686488ab227d32fbe";


    public static void main(String[] args) throws InterruptedException {
        OpenAiApi openAiApi = OpenAiApi.builder()
                .apiKey(apiKey)
                .baseUrl("https://dashscope.aliyuncs.com")
                .completionsPath("/compatible-mode/v1/chat/completions")
                .embeddingsPath("/embedding")
                .build();

        OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder()
                .model("qwen-max")
                .temperature(0.8)
                .maxTokens(200)
                .build();

        OpenAiChatModel chatModel = OpenAiChatModel.builder()
                .openAiApi(openAiApi)
                .defaultOptions(openAiChatOptions)
                .build();

        chatModel.stream("你是什么")
                .subscribe(System.out::print);

        Thread.sleep(60 * 1000);
    }
}
